package routers

import (
	"errors"

	"law-api-master/cm"
)

var (
	//ErrHTTPRequest is return when client post invalid http request
	ErrHTTPRequest = errors.New("invalid request")

	//ErrAccKey is return when client post a invalid private key to send Transaction
	ErrAccKey = errors.New("invalid private key")

	//ErrChainData is return when  client posts different formative chain datas to contract
	ErrChainData = errors.New("invalid chain data")

	//ErrTxHash is return client post a invalid txhash to verify chain data
	ErrTxHash = errors.New("invalid txhash")
)

//checkAddErrCode set error code to resposn add request
func checkAddErrCode(err error) int {
	switch err {
	case nil:
		return 0
	case ErrHTTPRequest:
		return 1
	case cm.ErrAccInit:
		return 2
	default:
	}
	return -1
}

//checkUploadErrCode set error code to resposn upload request
func checkUploadErrCode(err error) int {
	switch err {
	case nil:
		return 0
	case ErrHTTPRequest:
		return 1
	case ErrAccKey:
		return 2
	case ErrChainData:
		return 3
	case cm.ErrAccGas:
		return 4
	case cm.ErrAccNonce:
		return 5
	case cm.ErrTxTimeout, cm.ErrTxMissing:
		return 6
	case cm.ErrTxExisting, cm.ErrTxPending:
		return 7
	case cm.ErrTxInvalid, cm.ErrNetwork:
		return 8
	default:
	}
	return -1
}

//checkVerifyErrCode set error code to resposn verify request
func checkVerifyErrCode(err error) int {
	switch err {
	case nil:
		return 0
	case ErrHTTPRequest:
		return 1
	case ErrTxHash:
		return 2
	case cm.ErrTxPending:
		return 3
	case cm.ErrCtrCall:
		return 4
	default:
	}
	return -1
}

//checkVerifyErrCode set error code to resposn charge request
func checkChargeErrCode(err error) int {
	switch err {
	case nil:
		return 0
	case ErrHTTPRequest:
		return 1
	case cm.ErrAccInit:
		return 2
	case cm.ErrTxTimeout:
		return 3
	default:
	}
	return -1
}
